package com.Lyf.manager.service.impl;

import com.Lyf.manager.constant.AESConstant;
import com.Lyf.manager.dao.ManagerDao;
import com.Lyf.manager.entity.Admin;
import com.Lyf.manager.service.ManagerService;
import com.Lyf.manager.util.AESUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
public class ManagerServiceImpl implements ManagerService {

    @Resource
    private ManagerDao managerDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Admin login(String username, String password) {

        //根据用户名取数据库查询用户信息
       Admin admin= managerDao.selectAdminByUsername(username);
        //如果admin对象不为空，则取出密码进行解密操作并和传入的密码进行比较
        if(admin != null){
            String adminPassword = admin.getAdmin_password();
            String decrypt = AESUtil.decrypt(adminPassword,AESConstant.KEY);
            if(password.equals(decrypt)){
                return admin;
            }
        }
       return admin;
    }
}
